package com.yonyou.pmclouds.billview.rmiimpl;

import com.alibaba.dubbo.config.annotation.Service;
import com.yonyou.pmclouds.ApplicationConsts;
import com.yonyou.pmclouds.basecom.entity.PageObject;
import com.yonyou.pmclouds.basecom.entity.SuperVO;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.billtype.entity.BillTypeVO;
import com.yonyou.pmclouds.billtype.rmiitf.BillTypeQuery;
import com.yonyou.pmclouds.billview.entity.BillViewQueryVO;
import com.yonyou.pmclouds.billview.rmitf.BillViewQueryService;
import com.yonyou.pmclouds.billview.rmitf.BillViewWrapService;
import com.yonyou.pmclouds.billview.rmitf.IBillViewBuziService;
import com.yonyou.pmclouds.project.entity.ProjectVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

@Service(interfaceClass = BillViewQueryService.class,version = ApplicationConsts.APPLICATION_VERSION, timeout = 10000)
public class BillViewQueryServiceImpl implements BillViewQueryService {

    @Autowired
    private BillViewWrapService billViewWrapService;
    @Autowired
    private BillTypeQuery billTypeQuery;

    @Override
    public PageObject<Object> queryBillViewList(BillViewQueryVO billViewQueryVO) throws BusinessException {

       PageObject<Object> resultVOs =  billViewWrapService.queryListByType(billViewQueryVO);

        return resultVOs;
    }

    @Override
    public ProjectVO[] queryPermProjectByOrg(String pkSrcOrg) {

        if(StringUtils.isEmpty(pkSrcOrg))
            return new ProjectVO[0];

        return billViewWrapService.queryPermProjectByOrg(pkSrcOrg);
    }

    @Override
    public SuperVO queryBillDetail(String billType, String pkBill) throws BusinessException {

        if(StringUtils.isEmpty(billType))
            throw new BusinessException("单据类型为空");

        if(StringUtils.isEmpty(pkBill))
            throw new BusinessException("单据主键为空");

        return billViewWrapService.queryBillDetail(billType, pkBill);
    }

    @Override
    public String getBusiObjectCode(String billType) throws BusinessException {

        BillTypeVO billTypeVO = billTypeQuery.queryBillByType(billType,"datumManage");

        return billTypeVO.getTableName();
    }


}
